<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>遮罩效果</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }

        body{
            background: url(./img/paris.jpg);
        }

        #mask{
            width: 100%;
            height: 100%;
            position: absolute;
            left: 0;
            top: 0;
            background-color: lightgray;
            opacity: 0.7;  /* 透明度 */
        }

        #ad{
            width: 320px;
            height: 300px;
            background-color: cadetblue;

            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -150px;
            margin-left: -160px;
        }

        #close{
            width: 30px;
            height: 30px;
            border: 3px solid red;
            border-radius: 50%;
            text-align: center;
            line-height: 30px;

            position: absolute;
            top: -15px;
            right: -15px;
        }
    </style>
</head>
<body>
    <div id="mask">
        <div id="ad">
            <div id="close">X</div>
        </div>
    </div>
</body>
<script>
    let mask = document.querySelector("#mask");
    let close = document.querySelector("#close");

    //先获取标签元素，再给当前标签添加点击事件
    close.onclick = function(){
        //等价于 css样式  display:none;
        mask.style.display = "none";
    }
</script>
</html>